package com.ymatou.iapi.thirdpartysync.testcase;

import java.util.List;

import net.sf.json.JSONArray;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.thirdpartysync.parameter.getValidCategoryListBean;
import com.ymatou.iapi.thirdpartysync.service.getValidCategoryListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.thirdpartysync.fenqilecategory;
import com.ymttest.database.model.thirdpartysync.fenqilecategoryExample;
import com.ymttest.database.sqlwapper.thirdpartysync.thirdpartysyncWapper;
/**
*获取有效的类目列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getValidCategoryList{
	private static getValidCategoryListBean getvalidcategorylistBean;
	private static getValidCategoryListCall getvalidcategorylistCall;
	fenqilecategory category=new fenqilecategory();
	fenqilecategoryExample categoryExample=new fenqilecategoryExample();
	thirdpartysyncWapper syncWapper=new thirdpartysyncWapper(); 
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取有效的类目列表");
	}

	@Before
	public void caseUp() {
		getvalidcategorylistBean=new getValidCategoryListBean();
		getvalidcategorylistCall=new getValidCategoryListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getvalidcategorylistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getValidCategoryList_001() {
		Logger.start(true,"正例-获取有效的类目列表");
		try {
			
			getvalidcategorylistCall.setData(getvalidcategorylistBean);
			getvalidcategorylistCall.callService();			
			//验证
			categoryExample.createCriteria().andActionEqualTo(0);
			List<fenqilecategory> categorys=syncWapper.selectByExample(categoryExample);
			JSONArray jsonArray=getvalidcategorylistCall.getCategory3IdList();
			Logger.verifyEquals(jsonArray.size(), categorys.size(), "验证返回的长度与数据库的长度一致");
			for (int i = 0; i < jsonArray.size(); i++) {
				Logger.verifyEquals(jsonArray.get(i),categorys.get(i).getFqlCategory3Id(), "验证返回的值与数据库的值一致");
			}

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_getValidCategoryList_002() {
		Logger.start(true,"反例-获取有效的类目列表-数据库没有有效的类目列表");
		try {

			getvalidcategorylistCall.setData(getvalidcategorylistBean);
			getvalidcategorylistCall.callService();		
			
			//验证
			categoryExample.createCriteria().andActionEqualTo(0);
			List<fenqilecategory> categorys=syncWapper.selectByExample(categoryExample);
			JSONArray jsonArray=getvalidcategorylistCall.getCategory3IdList();
			Logger.verifyEquals(jsonArray.size(), categorys.size(), "验证返回的长度与数据库的长度一致");
			for (int i = 0; i < jsonArray.size(); i++) {
				Logger.verifyEquals(jsonArray.get(i),categorys.get(i).getFqlCategory3Id(), "验证返回的值与数据库的值一致");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}